function LoginClassic(param) {
try{
	var that = this;
	
	this.j_login_form = null;
	this.j_login_email = null;
	this.j_login_password = null;
	this.j_login_email_error_msg = null;
	this.j_login_password_error_msg = null;
	this.j_login_submit = null;
	
	var email_correct = false;
	var username_correct = false;
	var password_correct = false;
	var tos_correct = false;

	var email_existing = false;
	
	var email_validation_locked = true;
	var password_validation_locked = true;
	
	var email_validation_ever_opened = false;
	var password_validation_ever_opened = false;
	
	var form_submiting = false;
	
	function __construct(p) {
	try{
		for(pkey in p) {
			if(pkey[0] != "_") {
				that[pkey] = p[pkey];
			}
		}
		that.j_login_submit.mousedown(loginSumbitMousedown);
		that.j_login_form.submit(loginFormSubmit);
		that.j_login_email.blur(emailInputBlur);
		that.j_login_password.blur(passwordInputBlur);
		that.j_login_email.change(emailInputChange);
		that.j_login_password.change(passwordInputChange);
		
	}catch(err) {
		alert(err);
	}
	}
		
	function emailInputChange() {
	try{
		if(email_validation_locked) {
			email_validation_locked = false;
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function emailInputBlur() {
	try{
		if(!form_submiting) {
			validateEmail();
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function passwordInputChange() {
	try{
		if(password_validation_locked) {
			password_validation_locked = false;
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function passwordInputBlur() {
	try{
		if(!form_submiting) {
			validatePassword();
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function validateEmail() {
	try{
		if(!email_validation_locked) {
			email_validation_locked = true;
	    	if(!email_validation_ever_opened) {
	    		email_validation_ever_opened = true;
	    	}
			var email = that.j_login_email.val();
			var emailLength = jq.trim(email).length;
	
			// check required
			if(!emailLength) {
				email_correct = false;
				that.j_login_email.data({ 'errorMsg' : "Must not be empty" });
				showWarningMsg(that.j_login_email, that.j_login_email_error_msg);
				return false;
			}
			// check regex
			if(email.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/) == -1) {
				email_correct = false;
				that.j_login_email.data({ 'errorMsg' : "Not a valid email" });
				showWarningMsg(that.j_login_email, that.j_login_email_error_msg);
				return false;
			}
			email_correct = true;
			removeWarningMsg(that.j_login_email, that.j_login_email_error_msg);
		}else {
			// do nothing
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function validatePassword() {
	try{
		if(!password_validation_locked) {
			password_validation_locked = true;
	    	if(!password_validation_ever_opened) {
	    		password_validation_ever_opened = true;
	    	}
			
	    	if(!password_validation_ever_opened) {
	    		email_validation_ever_opened = true;
				email_validation_locked = false;
	    	}
			var password = that.j_login_password.val();
			var passLength = jq.trim(password).length;
			
			// check required
			if(!passLength) {
				password_correct = false;
				that.j_login_password.data({ 'errorMsg' : "Must not be empty" });
				showWarningMsg(that.j_login_password, that.j_login_password_error_msg);
				return false;
			}
			// check minimum length
			if(passLength < 6) {
				password_correct = false;
				that.j_login_password.data({ 'errorMsg' : "At least 6 characters" });
				showWarningMsg(that.j_login_password, that.j_login_password_error_msg);
				return false;
			}
			// check maximum length
			if(passLength > 20) {
				password_correct = false;
				that.j_login_password.data({ 'errorMsg' : "Less than 20 characters" });
				showWarningMsg(that.j_login_password, that.j_login_password_error_msg);
				return false;
			}
			// check regex
			if(password.search(/^[a-zA-Z0-9_]{6,20}$/) == -1) {
				password_correct = false;
				that.j_login_password.data({ 'errorMsg' : "Not a valid password" });
				showWarningMsg(that.j_login_password, that.j_login_password_error_msg);
				return false;
			}
			
			password_correct = true;
			removeWarningMsg(that.j_login_password, that.j_login_password_error_msg);
		}else {
			// do nothing
		}
	}catch(err) {
		alert(err);
	}
	}
	
	function loginSumbitMousedown(e) {
	try{
		form_submiting = true;
		
	}catch(err) {
		alert(err);
	}
	}
	
	function loginFormSubmit(e) {
	try{
    	e.preventDefault();

    	if(!email_validation_ever_opened) {
    		email_validation_ever_opened = true;
			email_validation_locked = false;
    	}
    	if(!password_validation_ever_opened) {
    		password_validation_ever_opened = true;
			password_validation_locked = false;
    	}
    	
		var loginForm = this;
		
		validateEmail();
		validatePassword();

		form_submiting = false;
		if(email_correct && password_correct) {
			loginForm.submit();
			return true;
		}
		return false;
		
	}catch(err) {
		alert(err);
	}
	}
	
	function showWarningMsg(inputEl, errEl) {
		if (!inputEl.hasClass("error")){
			inputEl.addClass("error");
		}
		errEl.text(inputEl.data("errorMsg"));
		if(!errEl.is(":visible")) {
			errEl.show();
		}
	}
	
	function removeWarningMsg(inputEl, errEl) {
		if(inputEl.hasClass("error")) {
			inputEl.removeClass("error");
		}
		if(errEl.is(":visible")) {
			errEl.hide();
		}
	}
	
	__construct(param);
	
	that.j_login_email.focus();
	
}catch(err) {
	alert(err);
}
}
